

$(function() {
			var options = {
				queryKey : queryKey,
				pageSize : 30,
				gridWidth : null,
				gridHeight : 580,
				showIdx : false,
				// init param for groove.query, property querykey is reserved,
				// property method is reserved,
				// init param for groove.view, property id is reserved
				gridRender : function(grid) {

				}
			};
			var gridPanel = new $.grooveQuery(options);

			$("#pageloading").hide();
		});

function defaultFnRender(rowdata, rowindex, value, column) {
	if (column.name == "FC_STATUS") {
		if (value == -1) {
			return "作废";
		} else if (value == 0) {
			return "执行中";
		} else if (value == 1) {
			return "变更";
		} else if (value == 2) {
			return "归档";
		}
	} else if (column.name == "FC_NUMBER") {
		return "<a href=\"javascript:void(0);\" title=\"贷款合同信息查阅\" onclick=\"viewContract('"
				+ rowdata["PK_ID"] + "')\">" + value + "</a>";
	} else if (column.name == "FC_DATE" || column.name == "FC_TIME"
			|| column.name == "ML_THISDATE" || column.name == "ML_DUEDATE") {
		return formatDate(value);
	} else if (column.name == "SP") {
		if (rowdata["FC_STATUS"] == 0) {
			return "<a href=\"javascript:void(0);\" onclick=\"makeloanlist('"
					+ rowdata["PK_ID"]
					+ "', '"
					+ rowdata["FC_NUMBER"]
					+ "')\">放款查询</a>&nbsp;<a href=\"javascript:void(0);\" onclick=\"makeloan('"
					+ rowdata["PK_ID"] + "')\">放款</a>";
		}
	}
	return value;
}

function viewContract(id) {
	var jsonparams = {
		id : id,
		primaryTable : "financialContract"
	}

	var editDialog;

	new $.grooveViewPreII(jsonparams, "viewcreditcontract", {
				formID : "formID",
				mode : "view",
				beforecall : function() {
					$("#target1").css("display", "none");
				},
				aftercall : function() {
					editDialog.hide();

					ligerGrid.reload();
				},
				rendercall : function(selfFunc, validator, validators,
						viewConfig) {
					editDialog = $.ligerDialog.open({
								title : "贷款合同信息预览窗口",
								target : $("#target1"),
								height : 500,
								width : 800,
								buttons : [{
											text : '关闭',
											onclick : function(item, dialog) {
												dialog.hide();
											}
										}],
								isResize : true
							});
				}
			});
}

function makeloanlist(id, name) {
	$("#pageloading").show();
	var editDialog = $.ligerDialog.open({
				title : "《" + name + "》放款记录",
				target : $("#makeloanlist"),
				height : 600,
				width : 800,
				isResize : true
			});

	var options = {
		queryKey : "makeloanlist",
		pageSize : 30,
		gridWidth : 770,
		gridHeight : 500,
		showIdx : false,
		params : {
			contractId : id
		},
		// init param for groove.query, property querykey is reserved,
		// property method is reserved,
		// init param for groove.view, property id is reserved
		gridRender : function(grid) {

		}
	};
	var gridPanel = new $.grooveQuery(options);

	$("#pageloading").hide();
}

function makeloan(id) {
	var editDialog;

	var jsonparams = {
		id : id,
		primaryTable : "financialContract"
	}

	new $.grooveViewPreII(jsonparams, "viewcreditcontract", {
		formID : "formView",
		beforecall : function() {

		},
		aftercall : function() {

		},
		rendercall : function(selfFunc, validator, validators, data) {

			new $.grooveView("addmakeloan", {
						formID : "formID2",
						mode : "insert",
						params : {
							contractId : id
						},
						beforecall : function() {
							$("#target2").css("display", "none");
						},
						aftercall : function() {
							editDialog.hide();
						},
						rendercall : function(selfFunc, validator, validators,
								viewConfig) {
							editDialog = $.ligerDialog.open({
										title : "贷款放款操作窗口",
										target : $("#target2"),
										height : 600,
										width : 800,
										buttons : [{
											text : '放款',
											onclick : function(item, dialog) {
												$("#formID2").handleSubmit(
														selfFunc, validator,
														validators, viewConfig);
											}
										}, {
											text : '关闭',
											onclick : function(item, dialog) {
												dialog.hide();
											}
										}],
										isResize : true
									});
						}
					});
		}
	});
}